<template>
	<view class="QrSite">
		<view class="PsFs" v-if="GoodsList.isGood  != 0">
			<view class="mdzt" v-for="(item,index) in list" :class="indexValue == index?'mdzt_color':''"
				@click="PSfz(index)">{{item.label}}</view>
		</view>
		<view class="location" @click="Golocation()" v-if="indexValue == 1">
			<span v-if="locationList == ''">添加收货地址</span>
			<span v-else v-for="(item,index) in locationList">
				<span v-if="item.isDefault == 1">
					{{item.provinceCityDistrict}}
				</span>
			</span>
		</view>
		<!-- <view v-else class="location"  @click="Golocation()">
			<span  v-for="(item,index) in locationList" >
				<span v-if="item.isDefault == 1" @click()>
					请选择
				</span>
			</span>
		</view> -->
		<view class="Goods_show" v-for="item in GoodsList">
			<view class="Goods_title">
				{{item.businessName}}
			</view>
			<view class="Goods_info">
				<view class="Goods_info_image">
					<image :src="item.image"></image>
				</view>
				<view class="Goods_info_public">
					<view class="Goods_info_title">
						<view class="">
							{{item.storeName}}
						</view>
						<view class="">
							￥{{item.price}}
						</view>
					</view>
					<view class="Goods_info_number">
						×{{item.cartNum}}
					</view>
				</view>

			</view>
			<view class="location_info">
				<span>配送方式</span>
				<span>快递接收</span>
			</view>
			<view class="Goods_word">
				<view class="Goods_word_title">
					<view>买家留言</view>
					<textarea v-model="status" placeholder="可以填写与卖家达成的协议"></textarea>
				</view>
			</view>
		</view>
		<view class="Goods_xx">
			<view>共计{{number}}件商品，小计：</view><span>￥{{Xprice}}.00</span>
		</view>
		<view class="Goods_Dxx">
			<view class="Goods_Dxx_price">
				<view>
					商品总金额
				</view>
				<view>
					￥{{Dprice}}
				</view>
			</view>
			<view class="Goods_location">
				<view>运费</view>
				<view>￥{{postAge}}.00</view>
			</view>
		</view>
		<view class="Boottom_button">
			<view class="B_title">
				合计金额:￥<span>{{Sprice}}.00</span>
			</view>
			<view class="B_button">
				<u-button type="success" shape="circle" text="确认支付" @click="GetPay()"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indexValue: 1,
				GoodsList: [],
				number: '',
				Xprice: 0,
				Dprice: 0,
				Sprice: 0,
				postAge: 0,
				locationList: [],
				status: '',
				cateId: '',
				locationId: '',
				list: [{
					label: '门店自提'
				}, {
					label: '物流配送'
				}]
			}
		},
		methods: {
			PSfz(e) {
				this.indexValue = e
			},
			GetPay() {
				// #ifdef H5
				let orderSrc = 1
				// #endif
				// #ifdef MP-WEIXIN
				let orderSrc = 2
				// #endif
				// #ifdef APP-PLUS
				let orderSrc = 3
				// #endif
				if (this.locationId === '') {
					uni.showToast({
						title: '收货地址不能为空',
						icon: 'error'
					})
				} else {
					this.$http({
						url: '/crmOrder/insShoppingCrmOrder',
						data: {
							deliveryStatus: '1',
							deliverMoney: this.postAge,
							totalAmount: this.Dprice,
							amount: this.Sprice,
							orderSrc: orderSrc,
							harvestAddressId: this.locationId,
							CartIds: this.cateId,
							orderType: 0
						}
					}).then(res => {
						if (res.data.code === 200) {
							uni.navigateTo({
								url: '/pages/bayPay/bayPay?id=' + res.data.data.orderNo
							})
						}
					})
				}
			},
			Golocation() {
				if (this.indexValue == 1) {
					uni.navigateTo({
						url: '/pages/locationGo/locationGo'
					})
				} else {
					// uni.navigateTo({
					// 	url:
					// })
				}
			},
			SearchLocation() {
				this.$http({
					url: '/crmUserAddress/selCrmUserAddress'
				}).then(res => {
					this.locationList = res.data.data
					res.data.data.map(item => {
						if (item.isDefault == 1) {
							this.locationId = item.id
						}
					})

				})
			},
			SearchGoods(id) {
				this.$http({
					url: '/crmStoreCart/settlementCart',
					data: {
						ids: id
					}
				}).then(res => {
					this.GoodsList = res.data.data
					if (this.GoodsList != '') {
						this.number = this.GoodsList.length
					}
					this.GoodsList.map(item => {
						this.Dprice = this.Dprice + item.price * item.cartNum
						this.postAge = this.postAge + item.postage
						return this.Xprice = item.cartNum * item.price
					})

					this.Sprice = this.postAge + this.Dprice
					this.SearchLocation()
				})
			}
		},
		onLoad(option) {
			this.SearchGoods(option.id)
			this.cateId = option.id
		},
		onShow() {
			this.SearchLocation()
		}
	}
</script>

<style>
	@import './index.css';
</style>
